package project.parser.ast.exps;

import project.environments.DynamicEnv;
import project.environments.StaticEnv;
import project.environments.Value;
import project.parser.ast.aux.Args;
import project.parser.ast.types.FuncType;
import project.parser.ast.types.Type;
import project.parser.ast.values.FuncValue;

public class FuncCall implements Exp {
	private final Ident id;
	private final Args args;

	public FuncCall(Ident id, Args args) {
		this.id = id;
		this.args = args;
	}

	@Override
	public Type typecheck(StaticEnv senv) {
		FuncType funcType = senv.funcLookup(id);
		funcType.argsChek(senv, args);
		return funcType.getReturnType();
	}

	@Override
	public Value evaluate(DynamicEnv denv) {
		FuncValue funcValue = denv.funcLookup(id);
		return funcValue.asFunction().call(denv, args);
	}
}
